package com.ruoyi.jiajia.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.JiajiaAppraise;
import com.ruoyi.system.domain.JiajiaWorkerTimeConfig;
import com.ruoyi.system.domain.JiajiaWorkerTimeXxConfig;
import com.ruoyi.system.service.IJiajiaWorkerTimeConfigService;
import com.ruoyi.system.service.IJiajiaWorkerTimeXxConfigService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 社工休息时间配置Controller
 * 
 * @author mrwang
 * @date 2024-04-25
 */
@Controller
@RequestMapping("/jiajia/rest/config")
public class ApiWorkerTimeRestConfigController extends BaseController
{

    private String prefix = "jiajia/restconfig";

    @Autowired
    private IJiajiaWorkerTimeXxConfigService jiajiaWorkerTimeXxConfigService;

    @Autowired
    private IJiajiaWorkerTimeConfigService jiajiaWorkerTimeConfigService;

    @RequiresPermissions("jiajia:restconfig:view")
    @GetMapping()
    public String config()
    {
        return prefix + "/jiajiarest";
    }

    /**
     * 查询社工休息时间配置列表
     */
    @RequiresPermissions("jiajia:restconfig:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JiajiaWorkerTimeXxConfig jiajiaWorkerTimeXxConfig) {
        startPage();
        List<JiajiaWorkerTimeXxConfig> list = jiajiaWorkerTimeXxConfigService.selectJiajiaWorkerTimeXxConfigList(jiajiaWorkerTimeXxConfig);
        return getDataTable(list);
    }

    @RequiresPermissions("jiajia:restconfig:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiajiaWorkerTimeXxConfig jiajiaWorkerTimeXxConfig) {
        List<JiajiaWorkerTimeXxConfig> list = jiajiaWorkerTimeXxConfigService.selectJiajiaWorkerTimeXxConfigList(jiajiaWorkerTimeXxConfig);
        ExcelUtil<JiajiaWorkerTimeXxConfig> util = new ExcelUtil<JiajiaWorkerTimeXxConfig>(JiajiaWorkerTimeXxConfig.class);
        return util.exportExcel(list, "社工休息时间配置列表");
    }

    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存社工休息时间配置
     */
    @RequiresPermissions("jiajia:restconfig:add")
    @Log(title = "社工休息时间配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiajiaWorkerTimeXxConfig jiajiaWorkerTimeXxConfig) {
        return toAjax(jiajiaWorkerTimeXxConfigService.insertJiajiaWorkerTimeXxConfig(jiajiaWorkerTimeXxConfig));
    }

    /**
     * 修改评价
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        JiajiaWorkerTimeXxConfig timeRestConfig = jiajiaWorkerTimeXxConfigService.selectJiajiaWorkerTimeXxConfigById(id);
        mmap.put("timeRestConfig", timeRestConfig);
        return prefix + "/edit";
    }

    /**
     * 修改保存社工休息时间配置
     */
    @RequiresPermissions("jiajia:restconfig:edit")
    @Log(title = "社工休息时间配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiajiaWorkerTimeXxConfig jiajiaWorkerTimeXxConfig) {
        return toAjax(jiajiaWorkerTimeXxConfigService.updateJiajiaWorkerTimeXxConfig(jiajiaWorkerTimeXxConfig));
    }

    /**
     * 删除社工休息时间配置
     */
    @RequiresPermissions("jiajia:restconfig:remove")
    @Log(title = "社工休息时间配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(jiajiaWorkerTimeXxConfigService.deleteJiajiaWorkerTimeXxConfigByIds(ids));
    }

    /**
     * 查询社工接单时间配置列表
     */
    @PostMapping("/configList")
    @ResponseBody
    public TableDataInfo configList(JiajiaWorkerTimeConfig jiajiaWorkerTimeConfig) {
        startPage();
        List<JiajiaWorkerTimeConfig> list = jiajiaWorkerTimeConfigService.selectJiajiaWorkerTimeConfigList(jiajiaWorkerTimeConfig);
        return getDataTable(list);
    }

}
